package com.zib.bilibili.view.fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.zib.bilibili.R;
import com.zib.bilibili.adapter.TuijianFragmentAdapter;
import com.zib.bilibili.base.BaseMvpFragment;
import com.zib.bilibili.bean.TuijianBean;
import com.zib.bilibili.presenter.impl.TuijianPresentImpl;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


public class TuijianFragment extends BaseMvpFragment<TuijianFragment, TuijianPresentImpl> {

    private TuijianFragmentAdapter adapter=null;
    private List<TuijianBean.ResultBean> totalList=new ArrayList<>();


    @Bind(R.id.xrecyclerview)
    XRecyclerView xrecyclerview;

    public TuijianFragment() {

    }

    public static TuijianFragment newInstance() {
        TuijianFragment fragment = new TuijianFragment();

        return fragment;
    }


    @Override
    protected TuijianPresentImpl initPresenter() {
        presenter = new TuijianPresentImpl(new TuijianPresentImpl.ICallback() {
            @Override
            public void onSuccess(TuijianBean obj) {
                   List<TuijianBean.ResultBean> list=obj.getResult();
                adapter.reloadRecyclerView(list,true);
            }

            @Override
            public void onfailure() {

            }
        });
        return presenter;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_tuijian;
    }

    @Override
    public void initView() {
        presenter.getTuijianBean();

        xrecyclerview.setHasFixedSize(true);
        LinearLayoutManager manager=new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false);
        xrecyclerview.setLayoutManager(manager);



       adapter=new TuijianFragmentAdapter(getContext(),totalList);
        xrecyclerview.setAdapter(adapter);


    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
